package com.itheima.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.mapper.QuestionsRecordsMapper;
import com.itheima.mapper.FrameMapper;
import com.itheima.pojo.BsUser;
import com.itheima.pojo.hm.SetRecords;
import com.itheima.pojo.pe.QuestionsRecords;
import com.itheima.service.QuestionsRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QuestionsRecordsServiceImpl implements QuestionsRecordsService {
    @Autowired
    private QuestionsRecordsMapper questionsRecordsMapper;
    @Autowired
    private FrameMapper userMapper;

    @Override
    public Object[] setRecords(Integer id) {//问题id
        LambdaQueryWrapper<QuestionsRecords> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(QuestionsRecords::getQuestionsID, id);
        List<QuestionsRecords> questionsRecords = questionsRecordsMapper.selectList(wrapper);
        System.out.println(questionsRecords);

        Object[] objects = new Object[questionsRecords.size()];

        for (int i = 0; i < questionsRecords.size(); i++) {
            SetRecords setRecords = new SetRecords();
            setRecords.setOperation(questionsRecords.get(i).getOperation());
            setRecords.setSetTime(questionsRecords.get(i).getSetTime().toString());
            BsUser bsUser = userMapper.selectById(questionsRecords.get(i).getSetterID());
            setRecords.setSetter(bsUser.getUsername());
            for (int j = -1; j < i; j++) {
                objects[i]=setRecords;
            }
        }

        return objects;
    }
}
